// 原型链

function SuperType() {
  this.property = true;
}

SuperType.prototype.getSuperValue = function () {
  return this.property;
};

function SubType() {
  this.subproperty = false;
}

SubType.prototype = new SuperType();

SubType.prototype.getSubValue = function () {
  return this.subproperty;
};

// 盗用构造函数

function SuperType() {
  this.colors = ["red", "blue", "green"];
}

function SubType() {
  SuperType.call(this);
}

// 组合继承

function SuperType(name) {
  this.name = name;
  this.colors = ["red", "blue", "green"];
}

SuperType.prototype.sayName = function () {
  console.log(this.name);
};

function SubType(name, age) {
  SuperType.call(this, name);

  this.age = age;
}

SubType.prototype = new SuperType();

SubType.prototype.sayAge = function () {
  console.log(this.age);
};

SubType.prototype.constructor = SubType;

// 原型式继承

function object(o) {
  function F() {}

  F.prototype = o;

  return new F();
}

// 寄生式继承

function createAnother(original) {
  let clone = object(original);

  clone.sayHi = function () {
    console.log("hi");
  };

  return clone;
}

// 寄生式组合继承

function inheritPrototype(subType, superType) {
  let prototype = object(superType.prototype);
  prototype.constructor = subType;
  subType.prototype = prototype;
}

function superType(name) {
  this.name = name;
  this.colors = ["red", "blue", "green"];
}
SuperType.prototype.sayName = function () {
  console.log(this.name);
};

function SubType(name, age) {
  SuperType.call(this, name);
  this.age = age;
}
inheritPrototype(SubType, SuperType);
SubType.prototype.sayAge = function () {
  console.log(this.age);
};

// 类继承

class S {
  constructor(a) {
    this.a = a;
  }

  getB() {
    return this.b;
  }
}

class T extends S {
  constructor(a) {
    super(a);

    this.b = 20;
  }

  getA() {
    console.log(super.getB());
    return this.a;
  }
}

let t = new T(1);

console.log(t.getA());

//console.log(t.getB());
